* Regresses estimated fixed effects preference and consistency parameters, as well as demographic and socio-economic variables, on moments of the choice data_choice_moments
* gets results for correlational comparison with Becker et al. (2012), simple regression exhibit in online Appendix, and for tables using point estimates of structural parameters to explain simple moments of the choice data

clear
set more off
pause on



cd ""


use base_FE_para_all
merge 1:1 ind_id using data_choice_moments
drop _merge

gen fe_theta=RP_th_t_base
gen fe_sig_th=RP_sig_th_t_base 
gen fe_kappa=RP_K_t_base
gen fe_r=RP_r_t_base 
gen fe_sig_r=RP_sig_r_t_base




*** Simple corr comparison with Becker (2012) (emotional stability is converse of neuroticism used by Becker)
foreach var of varlist sc_all_1stable sc_all_3extrav sc_all_4consci sc_all_2cognit {
		corr inv_lottery_index `var'
		corr inv_time_index `var'
}

	
*** Simple regression Online Appendix exhibit
local i=1	
foreach var of varlist inv_lottery_index inv_time_index  risk_reversal_n  time_reversal_n   {	
	reg `var' sex sc_all_1stable sc_all_3extrav sc_all_4consci sc_all_2cognit
	if `i'==1 {
		outreg2 using rev2_simple_reg.xls, replace dec(2) noomitted
		}
	else {
		outreg2 using rev2_simple_reg.xls, append dec(2) noomitted	
		}	

	local ++i	
	}
	


*** excludes outliers
drop if fe_theta>3 | fe_theta<-1

*** Can be used to replicate Table 5 and Table A7 of the paper
forvalues n=1/1 {
	if `n'==1 {
	local word=""
	}

		foreach var of varlist inv_lottery_index inv_time_index  risk_reversal_n  time_reversal_n risk_MPL_sd temp_switch_sd  {
			capture drop `word'r2_`var'
			* Records the r2 of each spec and also the pct contrib of the current spec compared to the full one
			gen `word'r2_`var'=.
			}

		* risk moments	
		local i=1
		foreach var of varlist inv_lottery_index risk_reversal_n risk_MPL_sd  {
			reg `var' `word'fe_theta 
			local prefs=`e(r2)'
			local run_tot=`e(r2)'	
			reg `var' `word'fe_sig_th `word'fe_kappa 
			local cons=`e(r2)'
			local struct=`prefs'+`cons'
			reg `var' `word'fe_sig_th 
			local st_risk=`e(r2)'
			local run_tot=`run_tot'+`e(r2)'
			reg `var' `word'fe_kappa
			local st_k=`e(r2)'
			local run_tot=`run_tot'+`e(r2)'
			local consist=`st_risk'+`st_k'
			
			* reg of moment on all estimated parameters
			reg `var' `word'fe_theta `word'fe_sig_th  `word'fe_kappa 
			replace `word'r2_`var'=`e(r2)' in 1
			
			
			* contribution of preference parameters towards explained variation, Table 5
			reg `var' `word'fe_theta 
			replace `word'r2_`var'=`e(r2)'/`struct' in 2

			* contribution of preference parameters towards explained variation
			reg `var' `word'fe_sig_th `word'fe_kappa 
			replace `word'r2_`var'=`e(r2)'/`struct' in 3
			* contribution of consistency parameters towards explained variation
			reg `var' `word'fe_sig_th 
			replace `word'r2_`var'=`e(r2)'/`consist' in 4
			
			* contribution of mistakes towards explained variation
			reg `var' `word'fe_kappa
			replace `word'r2_`var'=`e(r2)'/`consist' in 5

			
			* first row in Table, demographic and socio-economic variables
			reg `var' sex age* english p_uni_imp p_uni p_drop Q9_income_20_40 Q9_income_40_60 Q9_income_60_80 Q9_income_80_100 Q9_income_100plus p_native kidbornc  pnbchild wsiblings
			replace `word'r2_`var'=`e(r2)' in 7
			
			* contributions of individual parameters, Table A7
			* contribution of coefficient of risk aversion towards explained variation			
			reg `var' `word'fe_theta
			replace `word'r2_`var'=`e(r2)'/`run_tot' in 12
			* contribution of consistency of risk aversion towards explained variation		
			reg `var' `word'fe_sig_th 
			replace `word'r2_`var'=`e(r2)'/`run_tot' in 14		
			* contribution of mistakes towards explained variation
			reg `var' `word'fe_kappa
			replace `word'r2_`var'=`e(r2)'/`run_tot' in 16			
			
			local ++i
			}

		* time moments	
		local i=1
		foreach var of varlist inv_time_index  time_reversal_n  temp_switch_sd  {
			reg `var' `word'fe_theta `word'fe_r
			local prefs=`e(r2)'
			reg `var' `word'fe_sig_th `word'fe_sig_r `word'fe_kappa 
			local cons=`e(r2)'
			local struct=`prefs'+`cons'
			reg `var' `word'fe_sig_th `word'fe_sig_r
			local st_risk=`e(r2)'
			reg `var' `word'fe_kappa
			local st_k=`e(r2)'
			local consist=`st_risk'+`st_k'
			
			reg `var' `word'fe_theta 
			local run_tot=`e(r2)'	
			reg `var' `word'fe_r
			local run_tot=`run_tot'+`e(r2)'			
			reg `var' `word'fe_sig_th 
			local run_tot=`run_tot'+`e(r2)'
			reg `var' `word'fe_sig_r 
			local run_tot=`run_tot'+`e(r2)'			
			reg `var' `word'fe_kappa
			local run_tot=`run_tot'+`e(r2)'
						
			

			
			* reg of moment on all estimated parameters
			reg `var' `word'fe_theta `word'fe_sig_th `word'fe_r `word'fe_sig_r `word'fe_kappa 
			replace `word'r2_`var'=`e(r2)' in 1
			
			* contribution of preference parameters towards explained variation, Table 5
			reg `var' `word'fe_theta `word'fe_r
			replace `word'r2_`var'=`e(r2)'/`struct' in 2
			* contribution of consistency parameters towards explained variation
			reg `var' `word'fe_sig_th `word'fe_sig_r `word'fe_kappa 
			replace `word'r2_`var'=`e(r2)'/`struct' in 3
			* contribution of consistency parameters towards explained variation			
			reg `var' `word'fe_sig_th `word'fe_sig_r
			replace `word'r2_`var'=`e(r2)'/`consist' in 4
			* contribution of mistakes towards explained variation
			reg `var' `word'fe_kappa
			replace `word'r2_`var'=`e(r2)'/`consist' in 5

			* first row in Table, demographic and socio-economic variables			
			reg `var' sex age* english p_uni_imp p_uni p_drop Q9_income_20_40 Q9_income_40_60 Q9_income_60_80 Q9_income_80_100 Q9_income_100plus p_native kidbornc  pnbchild wsiblings
			replace `word'r2_`var'=`e(r2)' in 7
			
			* contributions of individual parameters, Table A7
			* contribution of coefficient of risk aversion towards explained variation			
			reg `var' `word'fe_theta
			replace `word'r2_`var'=`e(r2)'/`run_tot' in 12
			* contribution of discount rate towards explained variation									
			reg `var' `word'fe_r
			replace `word'r2_`var'=`e(r2)'/`run_tot' in 13			
			* contribution of consistency of risk aversion towards explained variation		
			reg `var' `word'fe_sig_th 
			replace `word'r2_`var'=`e(r2)'/`run_tot' in 14	
			* contribution of consistency of discount rate towards explained variation		
			reg `var' `word'fe_sig_r 
			replace `word'r2_`var'=`e(r2)'/`run_tot' in 15			
			* contribution of mistakes towards explained variation
			reg `var' `word'fe_kappa
			replace `word'r2_`var'=`e(r2)'/`run_tot' in 16						

			
			local ++i
			}
	}

browse r2_*





